package com.his.benchwork.controller;

import com.his.benchwork.entity.BenchWorkEmp;
import com.his.benchwork.service.BenchWorkConfigService;
import com.his.benchwork.service.BenchWorkEmpService;
import com.his.benchwork.service.BenchWorkService;
import com.his.benchwork.service.BenchConfigService;
import com.his.benchwork.vo.*;
import com.his.common.verification.group.Insert;
import com.his.config.annotation.CurrentUser;
import com.his.login.entity.DictEmployee;
import com.xiao.common.controller.ResultBaseController;
import com.xiao.common.util.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author jzy
 * @Date 2020/3/11 11:28
 * @Version 1.0
 */
@RestController
@RequestMapping(value="/api/benchwork")
public class BenchWorkController extends ResultBaseController {
    private  final org.slf4j.Logger logger = (Logger) LoggerFactory.getLogger(this.getClass());
    @Resource
    private BenchWorkService benchWorkService;

    @Resource
    private BenchConfigService benchConfigService;

    @Resource
    private BenchWorkEmpService benchWorkEmpService;

    @Resource
    private BenchWorkConfigService benchWorkConfigService;

    /****************************系统工作台配置*********************************/

    @PostMapping(value="/config.do")
    public ResultUtil selectByPrimaryKey(@RequestBody BenchConfigVo benchConfigVo){
        try {
            return this.success("成功", benchConfigService.selectByPrimaryKey(benchConfigVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    /**
     * 系统工作台配置列表查询
     * @param dictEmployee
     * @return
     */
    @PostMapping(value="/xt_config_list_all.do")
    public ResultUtil selectBench_configList_all(@CurrentUser DictEmployee dictEmployee){
        try {
            return this.success("系统工作台所有配置查询成功", benchConfigService.selectBench_configList_all(dictEmployee));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/xt_config_list.do")
    public ResultUtil selectBench_configList(@CurrentUser DictEmployee dictEmployee,@RequestBody BenchConfigVo benchConfigVo){
        try {
            return this.success("系统工作台配置查询成功", benchConfigService.selectBench_configList(benchConfigVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/xt_config_parm.do")
    public ResultUtil selectBench_config_parm(@CurrentUser DictEmployee dictEmployee){
        try {
            return this.success("系统工作台配置参数查询成功", benchConfigService.selectBench_config_parm());
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/xt_save_config.do")
    public ResultUtil insertBench_Config(@CurrentUser DictEmployee dictEmployee, @RequestBody @Validated({Insert.class}) BenchConfigVo benchConfigVo){
        try {
            benchConfigService.insertBench_Config(benchConfigVo);
            return this.success("新增系统配置成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/xt_update_config.do")
    public ResultUtil updateBench_Config(@CurrentUser DictEmployee dictEmployee, @RequestBody BenchConfigVo benchConfigVo){
        try {
            benchConfigService.updateBench_Config(benchConfigVo);
            return this.success("修改系统配置成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/delete_config.do")
    public ResultUtil deleteByPrimaryKey(@RequestBody String configId){
        try {
            benchConfigService.deleteByPrimaryKey(configId);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }


    /****************************医院工作台增删改*********************************/

    @PostMapping(value="/benchwork.do")
    public ResultUtil queryBenchWork(@CurrentUser String benchCateId,String benchName,String hospId){
        try {
            return this.success("成功", benchWorkService.qureyBenchWork(benchCateId,benchName,hospId));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/benchwork_list.do")
    public ResultUtil benchwork_list(@CurrentUser DictEmployee dictEmployee,@RequestBody BenchWorkVo benchWorkVo){
        try {
            return this.success("成功", benchWorkService.qureyBenchWorkList(dictEmployee,benchWorkVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    @PostMapping(value="/benchwork_parm.do")
    public ResultUtil benchwork_parm(@CurrentUser DictEmployee dictEmployee){
        try {
            return this.success("工作台查询参数成功", benchWorkService.qureyBenchWork_parm(dictEmployee));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    @PostMapping(value="/benchwork_save.do")
    public ResultUtil benchwork_save(@CurrentUser DictEmployee dictEmployee,@RequestBody @Validated BenchWorkVo benchWorkVo){
        try {
            benchWorkService.saveBenchWork(dictEmployee,benchWorkVo);
            return this.success("新增工作台成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/benchwork_update.do")
    public ResultUtil benchwork_update(@RequestBody BenchWorkVo benchWorkVo){
        try {
            benchWorkService.updateBenchWork(benchWorkVo);
            return this.success("工作台修改成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }



    /****************************工作台人员配置*********************************/
    @PostMapping(value="/select_emp.do")
    public ResultUtil selectBenchWorkEmpList(@RequestBody BenchWorkEmpVo benchWorkEmpVo){
        try {
            return this.success("成功", benchWorkEmpService.selectBenchWorkEmpList(benchWorkEmpVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/add_emp.do")
    public ResultUtil add_emp(@RequestBody List<BenchWorkEmpVo> benchWorkEmpVoList){
        try {
            benchWorkEmpService.addBenchWorkEmp(benchWorkEmpVoList);
            return this.success("新增操作员成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/delete_emp.do")
    public ResultUtil deleteBenchWorkEmp(@RequestBody BenchWorkEmpVo benchWorkEmpVo){
        try {
            benchWorkEmpService.deleteBenchWorkEmp(benchWorkEmpVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
    /****************************工作台与人员配置关系表*********************************/

    @PostMapping(value="/save_bwconfig.do")
    public ResultUtil save_bwconfig(@RequestBody @Validated({Insert.class}) BenchWorkConfigVo benchWorkConfigVo){
        try {
            benchWorkConfigService.insertBenchWorkConfig(benchWorkConfigVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/delete_bwconfig.do")
    public ResultUtil delete_bwconfig(@RequestBody BenchWorkConfigVo benchWorkConfigVo){
        try {
            benchWorkConfigService.deleteBenchWorkConfig(benchWorkConfigVo);
            return this.success("成功", null);
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/select_bwconfig_list.do")
    public ResultUtil select_bwconfig_list(@RequestBody BenchWorkConfigVo benchWorkConfigVo){
        try {
            return this.success("成功", benchWorkConfigService.selectBenchWorkConfigList(benchWorkConfigVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/select_bwconfig.do")
    public ResultUtil select_bwconfig(@RequestBody  BenchWorkConfigVo benchWorkConfigVo){
        try {
            return this.success("成功", benchWorkConfigService.select_bwconfig(benchWorkConfigVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }

    @PostMapping(value="/get_config.do")
    public ResultUtil getConfig(@CurrentUser DictEmployee dictEmployee,@RequestBody GetConfigVo getConfigVo){
        try {
            return this.success("成功", benchConfigService.getBenchConfig(dictEmployee,getConfigVo));
        }catch (Exception e){
            e.printStackTrace();
            logger.error(e.getMessage());
            return this.fail(e.getMessage(),null);
        }
    }
}
